home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / mac / Sample Code / QuickTime / QuickTimeIntro / Play Movie w⁄Controller / Completed Lab / SetupController.c < prev   
Encoding:
Text File  |  2000-10-06  |  2.9 KB  |  112 lines  |  [TEXT/CWIE]

  1. // Play Movie with Controller Sample
  2. // Based on QTShell
  3. // WWDC 2000
  4.  
  5. #include "ComApplication.h"
  6. #include "ComFramework.h"
  7. #include "MacFramework.h"
  8.  
  9. extern Rect gMCResizeBounds;    // maximum size for any movie window
  10.  
  11. //////////
  12. //
  13. // CreateController
  14. // Create and configure the movie controller.
  15. //
  16. //////////
  17.  
  18. MovieController CreateController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow)
  19. {
  20. #if TARGET_OS_WIN32
  21. #pragma unused(theMoveWindow)
  22. #endif
  23.  
  24.     MovieController            myMC = NULL;
  25.     Rect                    myRect;
  26.     WindowObject            myWindowObject = NULL;
  27.     GrafPtr                    mySavedPort;
  28.  
  29.     if ((theMovie == NULL) || (theWindow == NULL))
  30.         return(NULL);
  31.         
  32.     // get our window specific data
  33.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  34.     if (myWindowObject == NULL)
  35.         return(NULL);
  36.         
  37.     GetPort(&mySavedPort);
  38.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  39.     
  40.     // resize the movie bounding rect and offset to 0,0
  41.     GetMovieBox(theMovie, &myRect);
  42.     MacOffsetRect(&myRect, -myRect.left, -myRect.top);
  43.     SetMovieBox(theMovie, &myRect);
  44.     AlignWindow(QTFrame_GetWindowFromWindowReference(theWindow), false, &myRect, NULL);
  45.  
  46.     // create the movie controller
  47.     myMC = NewMovieController(theMovie, &myRect, mcTopLeftMovie);
  48.     if (myMC == NULL)
  49.         return(NULL);
  50.         
  51.     // enable the default movie controller editing
  52.     MCEnableEditing(myMC, true);
  53.         
  54.     // suppress movie badge
  55.     MCDoAction(myMC, mcActionSetUseBadge, (void *)false);
  56.  
  57.     // set the initial looping state of the movie
  58.     QTUtils_SetLoopingStateFromFile(theMovie, myMC);
  59.     
  60.     // install an action filter that does any application-specific movie controller action processing
  61.     MCSetActionFilterWithRefCon(myMC, NewMCActionFilterWithRefConProc(myMCActionFilterProc), (long)myWindowObject);
  62.  
  63.     // add grow box for the movie controller
  64.     if ((**myWindowObject).fCanResizeWindow) {
  65. #if TARGET_OS_WIN32
  66.         RECT                myRect;
  67.  
  68.         GetWindowRect(GetDesktopWindow(), &myRect);
  69.         OffsetRect(&myRect, -myRect.left, -myRect.top);
  70.         QTFrame_ConvertWinToMacRect(&myRect, &gMCResizeBounds);
  71. #endif
  72. #if TARGET_OS_MAC
  73.         GetRegionBounds(GetGrayRgn(), &gMCResizeBounds);
  74. #endif
  75.  
  76.         MCDoAction(myMC, mcActionSetGrowBoxBounds, &gMCResizeBounds);
  77.     }
  78.     
  79. #if TARGET_OS_MAC
  80.     if (theMoveWindow)
  81.         MoveWindow(theWindow, kDefaultWindowX, kDefaultWindowY, false);
  82. #endif
  83.  
  84.     MacSetPort(mySavedPort);
  85.  
  86.     // add any application-specific controller functionality
  87.     SetupController(myMC);
  88.         
  89.     return(myMC);
  90. }
  91.  
  92. //////////
  93. //
  94. // SetupController
  95. // Configure the movie controller.
  96. //
  97. //////////
  98.  
  99. void SetupController (MovieController theMC)
  100. {
  101.     long            myControllerFlags;
  102.     
  103.     // CLUT table use
  104.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  105.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  106.  
  107.     // enable keyboard event handling
  108.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  109.     
  110.     // disable drag support
  111.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  112. }